package org.example.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.mapper.ResumeMapper;
import org.example.pojo.Job;
import org.example.pojo.PageBean;
import org.example.pojo.Resume;
import org.example.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ResumeServiceImpl implements ResumeService {

    @Autowired
    private ResumeMapper resumeMapper;

    @Override
    public Integer getResumeIdByUserId(Integer userId) {
        return resumeMapper.getResumeIdByUserId(userId);
    }

    @Override
    public void insertResume(Resume resume) {
        resumeMapper.insertResume(resume);
    }

    @Override
    public Resume selectByUserId(Integer userId) {
        return resumeMapper.selectByUserId(userId);
    }
    @Override
    public Resume selectByResumeId(Integer resumeId) {
        return resumeMapper.selectByResumeId(resumeId);
    }

    @Override
    public void updateResume(Resume resume) {
        resumeMapper.updateResume(resume);
    }

    @Override
    public List<Resume> findResumeByTags(String tags) {
        return resumeMapper.findResumeByTags(tags);
    }

    @Override
    public List<Resume> selectAllResume() {
        return resumeMapper.selectAllResume();
    }

    @Override
    public PageBean<Resume> list(Integer userId, String name, Integer pageNum, Integer pageSize) {
        //1.创建一个PageBean对象
        PageBean<Resume> pb = new PageBean<>();

        //2.开启分页插件功能
        PageHelper.startPage(pageNum, pageSize);

        //将数据转为Page类型
        try{
            List<Resume> resumes =  resumeMapper.selectByUserIdAndName(userId, name);
            Page<Resume> page = (Page<Resume>) resumes;

            //把数据填充到PageBean对象中
            pb.setTotal(page.getTotal());
            pb.setItem(page.getResult());
            return pb;
        }catch (Exception e){
            System.out.println(e.getMessage());
            return null;
        }
    }

    @Override
    public void updateStatus(Integer userId, int status) {
        resumeMapper.updateStatus(userId, status);
    }

}
